package Test.StirngTest;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        List<qwe> students = new ArrayList<>();
        students.add(new qwe("Alice", new BigDecimal("85.5"), new BigDecimal("165.0")));
        students.add(new qwe("Bob", new BigDecimal("90.0"), new BigDecimal("170.0")));
        students.add(new qwe("Charlie", new BigDecimal("80.0"), new BigDecimal("175.0")));
        students.add(new qwe("David", new BigDecimal("90.0"), null));

        Map<BigDecimal, BigDecimal> scoreToHeightSum = students.stream()
                .filter(item -> item.getHeight()!=null)
                .collect(Collectors.groupingBy(
                        qwe::getScore,
                        Collectors.mapping(qwe::getHeight, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
                ));
        Map<BigDecimal, Long> collect = students.stream()
                .collect(Collectors.groupingBy(
                        qwe::getHeight, Collectors.counting()
                ));
        System.out.println(collect);

//        for (Map.Entry<BigDecimal, BigDecimal> entry : scoreToHeightSum.entrySet()) {
//            BigDecimal score = entry.getKey();
//            BigDecimal heightSum = entry.getValue();
//
//            System.out.println("Score: " + score + ", Height Sum: " + heightSum);
//        }
    }
}

class qwe {
    private String name;
    private BigDecimal score;
    private BigDecimal height;

    public qwe(String name, BigDecimal score, BigDecimal height) {
        this.name = name;
        this.score = score;
        this.height = height;
    }

    public BigDecimal getHeight() {
        return height;
    }

    public BigDecimal getScore() {
        return score;
    }

    // 其他 getter 和 setter 方法
}